package com.dimbottom.entity.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiModel(description = "分页数据")
public class RPage<T> {

    @ApiModelProperty(value = "数据数组")
    private List<T> records;
    @ApiModelProperty(value = "当前页", example = "1")
    private long current;
    @ApiModelProperty(value = "单页最多显示的记录数", example = "20")
    private long size;
    @ApiModelProperty(value = "总页数", example = "4")
    private long pages;
    @ApiModelProperty(value = "总记录数", example = "76")
    private long total;

    public RPage(Page<T> page) {
        records = page.getRecords();
        current = page.getCurrent();
        size = page.getSize();
        pages = page.getPages();
        total = page.getTotal();
    }


    public static <T> Rest<RPage<T>> ok(Page<T> page) {
        RPage<T> trPage = new RPage<>(page);
        return RestBody.okData(trPage);
    }

}
